//go:generate sqlboiler postgres
package main

import (
	"database/sql"
	"fmt"
	"io/ioutil"
	"time"

	_ "github.com/lib/pq"

	"gitee.com/lwj8507/nggs/util"

	"db/test6/model_op"
)

func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}

const (
	dataSourceName = `host=192.168.1.61 dbname=postgres user=postgres password=@5*20fx2p7be`
)

func main() {
	ba, err := ioutil.ReadFile("mysql_json_data.json")
	checkErr(err)

	f := string(ba)
	//fmt.Println(f)

	//boil.DebugMode = true

	db, err := sql.Open("postgres", dataSourceName)
	checkErr(err)

	begin := time.Now()

	for i := 0; i < 1000000; i++ {
		data := fmt.Sprintf(f, i, i, util.GenRandomString(8))
		user := &model_op.User{
			Data: null.JSON{JSON: []byte(data), Valid: true},
		}
		err = user.Insert(db)
		checkErr(err)
	}

	//users, err := model_op.Users(db, qm.Where(`data->'$.name' like ?`, "%S1.%")).All()
	//for _, u := range users {
	//	fmt.Printf("id=%d\ndata=%s\n", u.ID, u.Data)
	//}

	fmt.Printf("cost %v\n", time.Now().Sub(begin))
}
